


// Distribution of the number of partners, per buyer/seller and date (month$\times$year)


* distribution of the number of French partners per buyerXproduct 


use $dataset, clear
id_group id_bp "iso2 buyer id_conc"
bys id_bp: egen count=count(export)
*drop if count==1
save temp, replace

collapse (mean) count (sum) export, by(iso2 buyer id_conc siren year month)
id_group id_bp "iso2 buyer id_conc"
collapse (sum) export (mean) count (count) count_seller=export, by(id_bp iso2 year month)

g c5p=0
replace c5p=1 if count>=5
g c10p=0
replace c10p=1 if count>=10
g c50p=0
replace c50p=1 if count>=50
collapse (sum) c5p c10p c50p (count) count_bp=id_bp, by(count_seller)
gsort count_seller
g cumulated_count_bp=sum(count_bp)
g cumulated_count_bp_5p=sum(c5p)
g cumulated_count_bp_10p=sum(c10p)
g cumulated_count_bp_50p=sum(c50p)
egen _=sum(count_bp)
replace cumulated_count_bp=cumulated_count_bp/_
drop _
foreach var in 5p 10p 50p{
	egen _=sum(c`var')
	replace cumulated_count_bp_`var'=cumulated_count_bp_`var'/_
	drop _
}
gr tw scatter cumulated_count_bp count_seller if count_seller<200 || scatter cumulated_count_bp_5p count_seller if count_seller<200 || scatter cumulated_count_bp_10p count_seller if count_seller<200 || scatter cumulated_count_bp_50p count_seller if count_seller<200, xscale(log) scheme(s1mono) xlabel(1 2 5 10 50 200) xtitle("Count partners within a month") ytitle("Share of buyers") legend(label(1 "All") label(2 "At least 5 transactions") label(3 "At least 10 transactions") label(4 "At least 50 transactions"))
gr export "$outputpath/figure_online_1a.pdf", replace  


use temp, clear
collapse (mean) count (sum) export, by(iso2 buyer id_conc siren year month)
id_group id_sp "siren id_conc"
collapse (sum) export (mean) count (count) count_buyer=export, by(id_sp iso2 year month)

g c5p=0
replace c5p=1 if count>=5
g c10p=0
replace c10p=1 if count>=10
g c50p=0
replace c50p=1 if count>=50
collapse (sum) c5p c10p c50p (count) count_sp=id_sp, by(count_buyer)
gsort count_buyer
g cumulated_count_sp=sum(count_sp)
g cumulated_count_sp_5p=sum(c5p)
g cumulated_count_sp_10p=sum(c10p)
g cumulated_count_sp_50p=sum(c50p)
egen _=sum(count_sp)
replace cumulated_count_sp=cumulated_count_sp/_
drop _
foreach var in 5p 10p 50p{
	egen _=sum(c`var')
	replace cumulated_count_sp_`var'=cumulated_count_sp_`var'/_
	drop _
}
gr tw scatter cumulated_count_sp count_buyer if count_buyer<200 || scatter cumulated_count_sp_5p count_buyer if count_buyer<200 || scatter cumulated_count_sp_10p count_buyer if count_buyer<200 || scatter cumulated_count_sp_50p count_buyer if count_buyer<200, xscale(log) scheme(s1mono) xlabel(1 2 5 10 50 200) xtitle("Count partners within a month") ytitle("Share of sellers") legend(label(1 "All") label(2 "At least 5 transactions") label(3 "At least 10 transactions") label(4 "At least 50 transactions"))
gr export "$outputpath/figure_online_1b.pdf", replace  

use temp, clear
collapse (mean) count (sum) export, by(iso2 buyer siren year month)
id_group id_bp "iso2 buyer"
collapse (sum) export (mean) count (count) count_seller=export, by(id_bp iso2 year month)

g c5p=0
replace c5p=1 if count>=5
g c10p=0
replace c10p=1 if count>=10
g c50p=0
replace c50p=1 if count>=50
collapse (sum) c5p c10p c50p (count) count_bp=id_bp, by(count_seller)
gsort count_seller
g cumulated_count_bp=sum(count_bp)
g cumulated_count_bp_5p=sum(c5p)
g cumulated_count_bp_10p=sum(c10p)
g cumulated_count_bp_50p=sum(c50p)
egen _=sum(count_bp)
replace cumulated_count_bp=cumulated_count_bp/_
drop _
foreach var in 5p 10p 50p{
	egen _=sum(c`var')
	replace cumulated_count_bp_`var'=cumulated_count_bp_`var'/_
	drop _
}
gr tw scatter cumulated_count_bp count_seller if count_seller<200 || scatter cumulated_count_bp_5p count_seller if count_seller<200 || scatter cumulated_count_bp_10p count_seller if count_seller<200 || scatter cumulated_count_bp_50p count_seller if count_seller<200, xscale(log) scheme(s1mono) xlabel(1 2 5 10 50 200) xtitle("Count partners within a month") ytitle("Share of buyers") legend(label(1 "All") label(2 "At least 5 transactions") label(3 "At least 10 transactions") label(4 "At least 50 transactions"))
gr export "$outputpath/figure_online_3a.pdf", replace

use temp, clear
collapse (mean) count (sum) export, by(iso2 buyer siren year month)
id_group id_sp "siren"
collapse (sum) export (mean) count (count) count_buyer=export, by(id_sp iso2 year month)

g c5p=0
replace c5p=1 if count>=5
g c10p=0
replace c10p=1 if count>=10
g c50p=0
replace c50p=1 if count>=50
collapse (sum) c5p c10p c50p (count) count_sp=id_sp, by(count_buyer)
gsort count_buyer
g cumulated_count_sp=sum(count_sp)
g cumulated_count_sp_5p=sum(c5p)
g cumulated_count_sp_10p=sum(c10p)
g cumulated_count_sp_50p=sum(c50p)
egen _=sum(count_sp)
replace cumulated_count_sp=cumulated_count_sp/_
drop _
foreach var in 5p 10p 50p{
	egen _=sum(c`var')
	replace cumulated_count_sp_`var'=cumulated_count_sp_`var'/_
	drop _
}
gr tw scatter cumulated_count_sp count_buyer if count_buyer<200 || scatter cumulated_count_sp_5p count_buyer if count_buyer<200 || scatter cumulated_count_sp_10p count_buyer if count_buyer<200 || scatter cumulated_count_sp_50p count_buyer if count_buyer<200, xscale(log) scheme(s1mono) xlabel(1 2 5 10 50 200) xtitle("Count partners within a month") ytitle("Share of sellers") legend(label(1 "All") label(2 "At least 5 transactions") label(3 "At least 10 transactions") label(4 "At least 50 transactions"))
gr export "$outputpath/figure_online_3b.pdf", replace


use $dataset, clear
id_group id_bp "iso2 buyer id_conc"
bys id_bp: egen count=count(export)
drop if count==1
collapse (mean) count (sum) export, by(iso2 buyer id_conc siren)
id_group id_bp "iso2 buyer id_conc"
collapse (sum) export (mean) count (count) count_seller=export, by(id_bp iso2)

g c5p=0
replace c5p=1 if count>=5
g c10p=0
replace c10p=1 if count>=10
g c50p=0
replace c50p=1 if count>=50
collapse (sum) c5p c10p c50p (count) count_bp=id_bp, by(count_seller)
gsort count_seller
g cumulated_count_bp=sum(count_bp)
g cumulated_count_bp_5p=sum(c5p)
g cumulated_count_bp_10p=sum(c10p)
g cumulated_count_bp_50p=sum(c50p)
egen _=sum(count_bp)
replace cumulated_count_bp=cumulated_count_bp/_
drop _
foreach var in 5p 10p 50p{
	egen _=sum(c`var')
	replace cumulated_count_bp_`var'=cumulated_count_bp_`var'/_
	drop _
}
gr tw scatter cumulated_count_bp count_seller if count_seller<200 || scatter cumulated_count_bp_5p count_seller if count_seller<200 || scatter cumulated_count_bp_10p count_seller if count_seller<200 || scatter cumulated_count_bp_50p count_seller if count_seller<200, xscale(log) scheme(s1mono) xlabel(1 2 5 10 50 200) xtitle("Count partners") ytitle("Share of buyers") legend(label(1 "All") label(2 "At least 5 transactions") label(3 "At least 10 transactions") label(4 "At least 50 transactions"))
gr export "$outputpath/figure_online_4.pdf", replace 

erase temp.dta 
